" Shortcuts
nnoremap <silent> <space>a :ALEInfo<lf>
nnoremap <silent> <space>e :wq<lf>
nnoremap <silent> <space>f :ALEFix<lf>
nnoremap <silent> <space>n :wn<lf>
nnoremap <silent> <space>q :q!<lf>
nnoremap <silent> <space>s :w<lf>
nnoremap <silent> <space>u :UltiSnipsEdit<lf>
nnoremap <silent> <space>v :execute "split ".g:vimdir."/vimrc"<lf>

" Shortcuts for Git
nnoremap <space>gs :Gstatus<lf>
nnoremap <space>ga :Gwrite<lf>
nnoremap <space>gc :Gcommit <bar> startinsert<lf>
nnoremap <space>gp :Gpush<lf>
nnoremap <space>gr :Gread<lf>
nnoremap <space>gl :Gpull<lf>

" Shortcuts for language server
nnoremap <space>lD :LspDeclaration<lf>
nnoremap <space>ld :LspDefinition<lf>
nnoremap <space>le :LspDocumentDiagnostics<lf>
nnoremap <space>lf :LspDocumentFormat<lf>
nnoremap <space>lh :LspHover<lf>
nnoremap <space>li :LspImplementation<lf>
nnoremap <space>lr :LspRename<lf>

" Other maps
if g:mobile
    inoremap ˇD Ď
    inoremap ˇN Ň
    inoremap ˇT Ť
    inoremap ˇd ď
    inoremap ˇn ň
    inoremap ˇt ť
    nnoremap : :call TempGdefault()<lf>:
    noremap E J
    noremap J E
    noremap K N
    noremap L R
    noremap N K
    noremap R L
    noremap e gj
    noremap j e
    noremap k n
    noremap l r
    noremap n gk
    noremap r l
    xnoremap : :call TempGdefault()<lf>gv:
else
    nnoremap , :call TempGdefault()<lf>:
    nnoremap : @:
    noremap H ^
    noremap L $
    nnoremap gj j
    nnoremap gk k
    nnoremap j gj
    nnoremap k gk
    xnoremap , :call TempGdefault()<lf>gv:
    xnoremap <space> <esc>
endif
nnoremap ", vi"<esc>`<hr„`>3lr“
nnoremap "; vi"<esc>`<hr“`>3lr”
nnoremap +i :Import<space>
nnoremap +v :set virtualedit=all<lf>
nnoremap -u "uyy"upVr-
nnoremap -v :set virtualedit=<lf>
nnoremap <cr> o<esc>
nnoremap <space> <nop>
nnoremap =u "uyy"upVr=
nnoremap cp viw<esc>:let @e = expand('<cword>')->PalindromizeEnding()<lf>a<c-r>e<esc>
nnoremap c* "cyiwmc:call RenameHelper()<cr>ciw
nnoremap g<cr> O<esc>
nnoremap <silent> gb :bnext<lf>
nnoremap <silent> gB :bprevious<lf>
nnoremap gm m
nnoremap zh <c-w>h
nnoremap zj <c-w>j
nnoremap zk <c-w>k
nnoremap zl <c-w>l
noremap <c-v> v
noremap <down> <nop>
noremap <left> <nop>
noremap <right> <nop>
noremap <up> <nop>
noremap v <c-v>
xnoremap ", "qdi„“<esc>"qP
xnoremap "; "qdi“”<esc>"qP
xnoremap _ :sort<lf>

function! RenameHelper() abort
    augroup RenameHelper
        autocmd!
        autocmd InsertLeave * execute '%substitute/\<' . @c . '\>/' . @. . '/g | normal! `c' | autocmd! RenameHelper
    augroup END
endfunction

function! TempGdefault() abort
    set gdefault
    let g:temp_gdefault = 1
    augroup TempGdefault
        autocmd!
        autocmd CmdLineEnter * if g:temp_gdefault | let g:temp_gdefault = 0 | else | set nogdefault | autocmd! TempGdefault | endif
    augroup END
endfunction
